<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - lcov.info.p - core/contracts/protocol/libraries/logic/src/core/contracts/protocol/libraries/logic/ValidationLogic.sol</title>
  <link rel="stylesheet" type="text/css" href="../../../../../../../../../../../gcov.css">
</head>

<body>

          <table width="100%" border=0 cellspacing=0 cellpadding=0>
            <tr><td class="title">LCOV - code coverage report</td></tr>
            <tr><td class="ruler"><img src="../../../../../../../../../../../glass.png" width=3 height=3 alt=""></td></tr>

            <tr>
              <td width="100%">
                <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="10%" class="headerValue"><a href="../../../../../../../../../../../index.html">top level</a> - <a href="index.html">core/contracts/protocol/libraries/logic/src/core/contracts/protocol/libraries/logic</a> - ValidationLogic.sol<span style="font-size: 80%;"> (source / <a href="ValidationLogic.sol.func-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="5%"></td>
            <td width="5%" class="headerCovTableHead">Coverage</td>
            <td width="5%" class="headerCovTableHead" title="Covered + Uncovered code">Total</td>
            <td width="5%" class="headerCovTableHead" title="Exercised code only">Hit</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">lcov.info.p</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntryHi">100.0&nbsp;%</td>
            <td class="headerCovTableEntry">132</td>
            <td class="headerCovTableEntry">132</td>
          </tr>
          <tr>
            <td class="headerItem">Test Date:</td>
            <td class="headerValue">2024-04-09 14:12:28</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntryHi">100.0&nbsp;%</td>
            <td class="headerCovTableEntry">17</td>
            <td class="headerCovTableEntry">17</td>
          </tr>
          <tr>
            <td></td>
            <td></td>
            <td></td>
            <td class="headerItem">Branches:</td>
            <td class="headerCovTableEntryHi">-</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">0</td>
          </tr>
                  <tr><td><img src="../../../../../../../../../../../glass.png" width=3 height=3 alt=""></td></tr>
                </table>
              </td>
            </tr>

            <tr><td class="ruler"><img src="../../../../../../../../../../../glass.png" width=3 height=3 alt=""></td></tr>
          </table>

          <table cellpadding=0 cellspacing=0 border=0>
            <tr>
              <td><br></td>
            </tr>
            <tr>
              <td>
<pre class="sourceHeading">             Branch data     Line data    Source code</pre>
<pre class="source">
<span id="L1"><span class="lineNum">       1</span>                 :             : // SPDX-License-Identifier: BUSL-1.1</span>
<span id="L2"><span class="lineNum">       2</span>                 :             : pragma solidity ^0.8.10;</span>
<span id="L3"><span class="lineNum">       3</span>                 :             : </span>
<span id="L4"><span class="lineNum">       4</span>                 :             : import {IERC20} from '../../../dependencies/openzeppelin/contracts/IERC20.sol';</span>
<span id="L5"><span class="lineNum">       5</span>                 :             : import {Address} from '../../../dependencies/openzeppelin/contracts/Address.sol';</span>
<span id="L6"><span class="lineNum">       6</span>                 :             : import {GPv2SafeERC20} from '../../../dependencies/gnosis/contracts/GPv2SafeERC20.sol';</span>
<span id="L7"><span class="lineNum">       7</span>                 :             : import {IReserveInterestRateStrategy} from '../../../interfaces/IReserveInterestRateStrategy.sol';</span>
<span id="L8"><span class="lineNum">       8</span>                 :             : import {IStableDebtToken} from '../../../interfaces/IStableDebtToken.sol';</span>
<span id="L9"><span class="lineNum">       9</span>                 :             : import {IScaledBalanceToken} from '../../../interfaces/IScaledBalanceToken.sol';</span>
<span id="L10"><span class="lineNum">      10</span>                 :             : import {IPriceOracleGetter} from '../../../interfaces/IPriceOracleGetter.sol';</span>
<span id="L11"><span class="lineNum">      11</span>                 :             : import {IAToken} from '../../../interfaces/IAToken.sol';</span>
<span id="L12"><span class="lineNum">      12</span>                 :             : import {IPriceOracleSentinel} from '../../../interfaces/IPriceOracleSentinel.sol';</span>
<span id="L13"><span class="lineNum">      13</span>                 :             : import {IPoolAddressesProvider} from '../../../interfaces/IPoolAddressesProvider.sol';</span>
<span id="L14"><span class="lineNum">      14</span>                 :             : import {IAccessControl} from '../../../dependencies/openzeppelin/contracts/IAccessControl.sol';</span>
<span id="L15"><span class="lineNum">      15</span>                 :             : import {ReserveConfiguration} from '../configuration/ReserveConfiguration.sol';</span>
<span id="L16"><span class="lineNum">      16</span>                 :             : import {UserConfiguration} from '../configuration/UserConfiguration.sol';</span>
<span id="L17"><span class="lineNum">      17</span>                 :             : import {Errors} from '../helpers/Errors.sol';</span>
<span id="L18"><span class="lineNum">      18</span>                 :             : import {WadRayMath} from '../math/WadRayMath.sol';</span>
<span id="L19"><span class="lineNum">      19</span>                 :             : import {PercentageMath} from '../math/PercentageMath.sol';</span>
<span id="L20"><span class="lineNum">      20</span>                 :             : import {DataTypes} from '../types/DataTypes.sol';</span>
<span id="L21"><span class="lineNum">      21</span>                 :             : import {ReserveLogic} from './ReserveLogic.sol';</span>
<span id="L22"><span class="lineNum">      22</span>                 :             : import {GenericLogic} from './GenericLogic.sol';</span>
<span id="L23"><span class="lineNum">      23</span>                 :             : import {SafeCast} from '../../../dependencies/openzeppelin/contracts/SafeCast.sol';</span>
<span id="L24"><span class="lineNum">      24</span>                 :             : import {IncentivizedERC20} from '../../tokenization/base/IncentivizedERC20.sol';</span>
<span id="L25"><span class="lineNum">      25</span>                 :             : </span>
<span id="L26"><span class="lineNum">      26</span>                 :             : /**</span>
<span id="L27"><span class="lineNum">      27</span>                 :             :  * @title ReserveLogic library</span>
<span id="L28"><span class="lineNum">      28</span>                 :             :  * @author Aave</span>
<span id="L29"><span class="lineNum">      29</span>                 :             :  * @notice Implements functions to validate the different actions of the protocol</span>
<span id="L30"><span class="lineNum">      30</span>                 :             :  */</span>
<span id="L31"><span class="lineNum">      31</span>                 :             : library ValidationLogic {</span>
<span id="L32"><span class="lineNum">      32</span>                 :             :   using ReserveLogic for DataTypes.ReserveData;</span>
<span id="L33"><span class="lineNum">      33</span>                 :             :   using WadRayMath for uint256;</span>
<span id="L34"><span class="lineNum">      34</span>                 :             :   using PercentageMath for uint256;</span>
<span id="L35"><span class="lineNum">      35</span>                 :             :   using SafeCast for uint256;</span>
<span id="L36"><span class="lineNum">      36</span>                 :             :   using GPv2SafeERC20 for IERC20;</span>
<span id="L37"><span class="lineNum">      37</span>                 :             :   using ReserveConfiguration for DataTypes.ReserveConfigurationMap;</span>
<span id="L38"><span class="lineNum">      38</span>                 :             :   using UserConfiguration for DataTypes.UserConfigurationMap;</span>
<span id="L39"><span class="lineNum">      39</span>                 :             :   using Address for address;</span>
<span id="L40"><span class="lineNum">      40</span>                 :             : </span>
<span id="L41"><span class="lineNum">      41</span>                 :             :   // Factor to apply to &quot;only-variable-debt&quot; liquidity rate to get threshold for rebalancing, expressed in bps</span>
<span id="L42"><span class="lineNum">      42</span>                 :             :   // A value of 0.9e4 results in 90%</span>
<span id="L43"><span class="lineNum">      43</span>                 :             :   uint256 public constant REBALANCE_UP_LIQUIDITY_RATE_THRESHOLD = 0.9e4;</span>
<span id="L44"><span class="lineNum">      44</span>                 :             : </span>
<span id="L45"><span class="lineNum">      45</span>                 :             :   // Minimum health factor allowed under any circumstance</span>
<span id="L46"><span class="lineNum">      46</span>                 :             :   // A value of 0.95e18 results in 0.95</span>
<span id="L47"><span class="lineNum">      47</span>                 :             :   uint256 public constant MINIMUM_HEALTH_FACTOR_LIQUIDATION_THRESHOLD = 0.95e18;</span>
<span id="L48"><span class="lineNum">      48</span>                 :             : </span>
<span id="L49"><span class="lineNum">      49</span>                 :             :   /**</span>
<span id="L50"><span class="lineNum">      50</span>                 :             :    * @dev Minimum health factor to consider a user position healthy</span>
<span id="L51"><span class="lineNum">      51</span>                 :             :    * A value of 1e18 results in 1</span>
<span id="L52"><span class="lineNum">      52</span>                 :             :    */</span>
<span id="L53"><span class="lineNum">      53</span>                 :             :   uint256 public constant HEALTH_FACTOR_LIQUIDATION_THRESHOLD = 1e18;</span>
<span id="L54"><span class="lineNum">      54</span>                 :             : </span>
<span id="L55"><span class="lineNum">      55</span>                 :             :   /**</span>
<span id="L56"><span class="lineNum">      56</span>                 :             :    * @dev Role identifier for the role allowed to supply isolated reserves as collateral</span>
<span id="L57"><span class="lineNum">      57</span>                 :             :    */</span>
<span id="L58"><span class="lineNum">      58</span>                 :             :   bytes32 public constant ISOLATED_COLLATERAL_SUPPLIER_ROLE =</span>
<span id="L59"><span class="lineNum">      59</span>                 :             :     keccak256('ISOLATED_COLLATERAL_SUPPLIER');</span>
<span id="L60"><span class="lineNum">      60</span>                 :             : </span>
<span id="L61"><span class="lineNum">      61</span>                 :             :   /**</span>
<span id="L62"><span class="lineNum">      62</span>                 :             :    * @notice Validates a supply action.</span>
<span id="L63"><span class="lineNum">      63</span>                 :             :    * @param reserveCache The cached data of the reserve</span>
<span id="L64"><span class="lineNum">      64</span>                 :             :    * @param amount The amount to be supplied</span>
<span id="L65"><span class="lineNum">      65</span>                 :             :    */</span>
<span id="L66"><span class="lineNum">      66</span>                 :<span class="tlaGNC tlaBgGNC">       13598 :   function validateSupply(</span></span>
<span id="L67"><span class="lineNum">      67</span>                 :             :     DataTypes.ReserveCache memory reserveCache,</span>
<span id="L68"><span class="lineNum">      68</span>                 :             :     DataTypes.ReserveData storage reserve,</span>
<span id="L69"><span class="lineNum">      69</span>                 :             :     uint256 amount,</span>
<span id="L70"><span class="lineNum">      70</span>                 :             :     address onBehalfOf</span>
<span id="L71"><span class="lineNum">      71</span>                 :             :   ) internal view {</span>
<span id="L72"><span class="lineNum">      72</span>                 :<span class="tlaGNC">       27196 :     require(amount != 0, Errors.INVALID_AMOUNT);</span></span>
<span id="L73"><span class="lineNum">      73</span>                 :             : </span>
<span id="L74"><span class="lineNum">      74</span>                 :<span class="tlaGNC">       40791 :     (bool isActive, bool isFrozen, , , bool isPaused) = reserveCache</span></span>
<span id="L75"><span class="lineNum">      75</span>                 :             :       .reserveConfiguration</span>
<span id="L76"><span class="lineNum">      76</span>                 :             :       .getFlags();</span>
<span id="L77"><span class="lineNum">      77</span>                 :<span class="tlaGNC">       27194 :     require(isActive, Errors.RESERVE_INACTIVE);</span></span>
<span id="L78"><span class="lineNum">      78</span>                 :<span class="tlaGNC">       27192 :     require(!isPaused, Errors.RESERVE_PAUSED);</span></span>
<span id="L79"><span class="lineNum">      79</span>                 :<span class="tlaGNC">       27190 :     require(!isFrozen, Errors.RESERVE_FROZEN);</span></span>
<span id="L80"><span class="lineNum">      80</span>                 :<span class="tlaGNC">       27188 :     require(onBehalfOf != reserveCache.aTokenAddress, Errors.SUPPLY_TO_ATOKEN);</span></span>
<span id="L81"><span class="lineNum">      81</span>                 :             : </span>
<span id="L82"><span class="lineNum">      82</span>                 :<span class="tlaGNC">       40779 :     uint256 supplyCap = reserveCache.reserveConfiguration.getSupplyCap();</span></span>
<span id="L83"><span class="lineNum">      83</span>                 :<span class="tlaGNC">       27186 :     require(</span></span>
<span id="L84"><span class="lineNum">      84</span>                 :             :       supplyCap == 0 ||</span>
<span id="L85"><span class="lineNum">      85</span>                 :             :         ((IAToken(reserveCache.aTokenAddress).scaledTotalSupply() +</span>
<span id="L86"><span class="lineNum">      86</span>                 :             :           uint256(reserve.accruedToTreasury)).rayMul(reserveCache.nextLiquidityIndex) + amount) &lt;=</span>
<span id="L87"><span class="lineNum">      87</span>                 :             :         supplyCap * (10 ** reserveCache.reserveConfiguration.getDecimals()),</span>
<span id="L88"><span class="lineNum">      88</span>                 :             :       Errors.SUPPLY_CAP_EXCEEDED</span>
<span id="L89"><span class="lineNum">      89</span>                 :             :     );</span>
<span id="L90"><span class="lineNum">      90</span>                 :             :   }</span>
<span id="L91"><span class="lineNum">      91</span>                 :             : </span>
<span id="L92"><span class="lineNum">      92</span>                 :             :   /**</span>
<span id="L93"><span class="lineNum">      93</span>                 :             :    * @notice Validates a withdraw action.</span>
<span id="L94"><span class="lineNum">      94</span>                 :             :    * @param reserveCache The cached data of the reserve</span>
<span id="L95"><span class="lineNum">      95</span>                 :             :    * @param amount The amount to be withdrawn</span>
<span id="L96"><span class="lineNum">      96</span>                 :             :    * @param userBalance The balance of the user</span>
<span id="L97"><span class="lineNum">      97</span>                 :             :    */</span>
<span id="L98"><span class="lineNum">      98</span>                 :<span class="tlaGNC">          44 :   function validateWithdraw(</span></span>
<span id="L99"><span class="lineNum">      99</span>                 :             :     DataTypes.ReserveCache memory reserveCache,</span>
<span id="L100"><span class="lineNum">     100</span>                 :             :     uint256 amount,</span>
<span id="L101"><span class="lineNum">     101</span>                 :             :     uint256 userBalance</span>
<span id="L102"><span class="lineNum">     102</span>                 :             :   ) internal pure {</span>
<span id="L103"><span class="lineNum">     103</span>                 :<span class="tlaGNC">          88 :     require(amount != 0, Errors.INVALID_AMOUNT);</span></span>
<span id="L104"><span class="lineNum">     104</span>                 :<span class="tlaGNC">          86 :     require(amount &lt;= userBalance, Errors.NOT_ENOUGH_AVAILABLE_USER_BALANCE);</span></span>
<span id="L105"><span class="lineNum">     105</span>                 :             : </span>
<span id="L106"><span class="lineNum">     106</span>                 :<span class="tlaGNC">         126 :     (bool isActive, , , , bool isPaused) = reserveCache.reserveConfiguration.getFlags();</span></span>
<span id="L107"><span class="lineNum">     107</span>                 :<span class="tlaGNC">          84 :     require(isActive, Errors.RESERVE_INACTIVE);</span></span>
<span id="L108"><span class="lineNum">     108</span>                 :<span class="tlaGNC">          82 :     require(!isPaused, Errors.RESERVE_PAUSED);</span></span>
<span id="L109"><span class="lineNum">     109</span>                 :             :   }</span>
<span id="L110"><span class="lineNum">     110</span>                 :             : </span>
<span id="L111"><span class="lineNum">     111</span>                 :             :   struct ValidateBorrowLocalVars {</span>
<span id="L112"><span class="lineNum">     112</span>                 :             :     uint256 currentLtv;</span>
<span id="L113"><span class="lineNum">     113</span>                 :             :     uint256 collateralNeededInBaseCurrency;</span>
<span id="L114"><span class="lineNum">     114</span>                 :             :     uint256 userCollateralInBaseCurrency;</span>
<span id="L115"><span class="lineNum">     115</span>                 :             :     uint256 userDebtInBaseCurrency;</span>
<span id="L116"><span class="lineNum">     116</span>                 :             :     uint256 availableLiquidity;</span>
<span id="L117"><span class="lineNum">     117</span>                 :             :     uint256 healthFactor;</span>
<span id="L118"><span class="lineNum">     118</span>                 :             :     uint256 totalDebt;</span>
<span id="L119"><span class="lineNum">     119</span>                 :             :     uint256 totalSupplyVariableDebt;</span>
<span id="L120"><span class="lineNum">     120</span>                 :             :     uint256 reserveDecimals;</span>
<span id="L121"><span class="lineNum">     121</span>                 :             :     uint256 borrowCap;</span>
<span id="L122"><span class="lineNum">     122</span>                 :             :     uint256 amountInBaseCurrency;</span>
<span id="L123"><span class="lineNum">     123</span>                 :             :     uint256 assetUnit;</span>
<span id="L124"><span class="lineNum">     124</span>                 :             :     address eModePriceSource;</span>
<span id="L125"><span class="lineNum">     125</span>                 :             :     address siloedBorrowingAddress;</span>
<span id="L126"><span class="lineNum">     126</span>                 :             :     bool isActive;</span>
<span id="L127"><span class="lineNum">     127</span>                 :             :     bool isFrozen;</span>
<span id="L128"><span class="lineNum">     128</span>                 :             :     bool isPaused;</span>
<span id="L129"><span class="lineNum">     129</span>                 :             :     bool borrowingEnabled;</span>
<span id="L130"><span class="lineNum">     130</span>                 :             :     bool stableRateBorrowingEnabled;</span>
<span id="L131"><span class="lineNum">     131</span>                 :             :     bool siloedBorrowingEnabled;</span>
<span id="L132"><span class="lineNum">     132</span>                 :             :   }</span>
<span id="L133"><span class="lineNum">     133</span>                 :             : </span>
<span id="L134"><span class="lineNum">     134</span>                 :             :   /**</span>
<span id="L135"><span class="lineNum">     135</span>                 :             :    * @notice Validates a borrow action.</span>
<span id="L136"><span class="lineNum">     136</span>                 :             :    * @param reservesData The state of all the reserves</span>
<span id="L137"><span class="lineNum">     137</span>                 :             :    * @param reservesList The addresses of all the active reserves</span>
<span id="L138"><span class="lineNum">     138</span>                 :             :    * @param eModeCategories The configuration of all the efficiency mode categories</span>
<span id="L139"><span class="lineNum">     139</span>                 :             :    * @param params Additional params needed for the validation</span>
<span id="L140"><span class="lineNum">     140</span>                 :             :    */</span>
<span id="L141"><span class="lineNum">     141</span>                 :<span class="tlaGNC">        9117 :   function validateBorrow(</span></span>
<span id="L142"><span class="lineNum">     142</span>                 :             :     mapping(address =&gt; DataTypes.ReserveData) storage reservesData,</span>
<span id="L143"><span class="lineNum">     143</span>                 :             :     mapping(uint256 =&gt; address) storage reservesList,</span>
<span id="L144"><span class="lineNum">     144</span>                 :             :     mapping(uint8 =&gt; DataTypes.EModeCategory) storage eModeCategories,</span>
<span id="L145"><span class="lineNum">     145</span>                 :             :     DataTypes.ValidateBorrowParams memory params</span>
<span id="L146"><span class="lineNum">     146</span>                 :             :   ) internal view {</span>
<span id="L147"><span class="lineNum">     147</span>                 :<span class="tlaGNC">       18234 :     require(params.amount != 0, Errors.INVALID_AMOUNT);</span></span>
<span id="L148"><span class="lineNum">     148</span>                 :             : </span>
<span id="L149"><span class="lineNum">     149</span>                 :<span class="tlaGNC">       18232 :     ValidateBorrowLocalVars memory vars;</span></span>
<span id="L150"><span class="lineNum">     150</span>                 :             : </span>
<span id="L151"><span class="lineNum">     151</span>                 :<span class="tlaGNC">       18232 :     (</span></span>
<span id="L152"><span class="lineNum">     152</span>                 :             :       vars.isActive,</span>
<span id="L153"><span class="lineNum">     153</span>                 :             :       vars.isFrozen,</span>
<span id="L154"><span class="lineNum">     154</span>                 :             :       vars.borrowingEnabled,</span>
<span id="L155"><span class="lineNum">     155</span>                 :             :       vars.stableRateBorrowingEnabled,</span>
<span id="L156"><span class="lineNum">     156</span>                 :             :       vars.isPaused</span>
<span id="L157"><span class="lineNum">     157</span>                 :             :     ) = params.reserveCache.reserveConfiguration.getFlags();</span>
<span id="L158"><span class="lineNum">     158</span>                 :             : </span>
<span id="L159"><span class="lineNum">     159</span>                 :<span class="tlaGNC">       18232 :     require(vars.isActive, Errors.RESERVE_INACTIVE);</span></span>
<span id="L160"><span class="lineNum">     160</span>                 :<span class="tlaGNC">       18230 :     require(!vars.isPaused, Errors.RESERVE_PAUSED);</span></span>
<span id="L161"><span class="lineNum">     161</span>                 :<span class="tlaGNC">       18228 :     require(!vars.isFrozen, Errors.RESERVE_FROZEN);</span></span>
<span id="L162"><span class="lineNum">     162</span>                 :<span class="tlaGNC">       18226 :     require(vars.borrowingEnabled, Errors.BORROWING_NOT_ENABLED);</span></span>
<span id="L163"><span class="lineNum">     163</span>                 :<span class="tlaGNC">       18226 :     require(</span></span>
<span id="L164"><span class="lineNum">     164</span>                 :             :       IERC20(params.reserveCache.aTokenAddress).totalSupply() &gt;= params.amount,</span>
<span id="L165"><span class="lineNum">     165</span>                 :             :       Errors.INVALID_AMOUNT</span>
<span id="L166"><span class="lineNum">     166</span>                 :             :     );</span>
<span id="L167"><span class="lineNum">     167</span>                 :             : </span>
<span id="L168"><span class="lineNum">     168</span>                 :<span class="tlaGNC">       18224 :     require(</span></span>
<span id="L169"><span class="lineNum">     169</span>                 :             :       params.priceOracleSentinel == address(0) ||</span>
<span id="L170"><span class="lineNum">     170</span>                 :             :         IPriceOracleSentinel(params.priceOracleSentinel).isBorrowAllowed(),</span>
<span id="L171"><span class="lineNum">     171</span>                 :             :       Errors.PRICE_ORACLE_SENTINEL_CHECK_FAILED</span>
<span id="L172"><span class="lineNum">     172</span>                 :             :     );</span>
<span id="L173"><span class="lineNum">     173</span>                 :             : </span>
<span id="L174"><span class="lineNum">     174</span>                 :             :     //validate interest rate mode</span>
<span id="L175"><span class="lineNum">     175</span>                 :<span class="tlaGNC">       18222 :     require(</span></span>
<span id="L176"><span class="lineNum">     176</span>                 :             :       params.interestRateMode == DataTypes.InterestRateMode.VARIABLE ||</span>
<span id="L177"><span class="lineNum">     177</span>                 :             :         params.interestRateMode == DataTypes.InterestRateMode.STABLE,</span>
<span id="L178"><span class="lineNum">     178</span>                 :             :       Errors.INVALID_INTEREST_RATE_MODE_SELECTED</span>
<span id="L179"><span class="lineNum">     179</span>                 :             :     );</span>
<span id="L180"><span class="lineNum">     180</span>                 :             : </span>
<span id="L181"><span class="lineNum">     181</span>                 :<span class="tlaGNC">       18220 :     vars.reserveDecimals = params.reserveCache.reserveConfiguration.getDecimals();</span></span>
<span id="L182"><span class="lineNum">     182</span>                 :<span class="tlaGNC">       18220 :     vars.borrowCap = params.reserveCache.reserveConfiguration.getBorrowCap();</span></span>
<span id="L183"><span class="lineNum">     183</span>                 :             :     unchecked {</span>
<span id="L184"><span class="lineNum">     184</span>                 :<span class="tlaGNC">       18220 :       vars.assetUnit = 10 ** vars.reserveDecimals;</span></span>
<span id="L185"><span class="lineNum">     185</span>                 :             :     }</span>
<span id="L186"><span class="lineNum">     186</span>                 :             : </span>
<span id="L187"><span class="lineNum">     187</span>                 :<span class="tlaGNC">       18220 :     if (vars.borrowCap != 0) {</span></span>
<span id="L188"><span class="lineNum">     188</span>                 :<span class="tlaGNC">          14 :       vars.totalSupplyVariableDebt = params.reserveCache.currScaledVariableDebt.rayMul(</span></span>
<span id="L189"><span class="lineNum">     189</span>                 :             :         params.reserveCache.nextVariableBorrowIndex</span>
<span id="L190"><span class="lineNum">     190</span>                 :             :       );</span>
<span id="L191"><span class="lineNum">     191</span>                 :             : </span>
<span id="L192"><span class="lineNum">     192</span>                 :<span class="tlaGNC">          14 :       vars.totalDebt =</span></span>
<span id="L193"><span class="lineNum">     193</span>                 :             :         params.reserveCache.currTotalStableDebt +</span>
<span id="L194"><span class="lineNum">     194</span>                 :             :         vars.totalSupplyVariableDebt +</span>
<span id="L195"><span class="lineNum">     195</span>                 :             :         params.amount;</span>
<span id="L196"><span class="lineNum">     196</span>                 :             : </span>
<span id="L197"><span class="lineNum">     197</span>                 :             :       unchecked {</span>
<span id="L198"><span class="lineNum">     198</span>                 :<span class="tlaGNC">          14 :         require(vars.totalDebt &lt;= vars.borrowCap * vars.assetUnit, Errors.BORROW_CAP_EXCEEDED);</span></span>
<span id="L199"><span class="lineNum">     199</span>                 :             :       }</span>
<span id="L200"><span class="lineNum">     200</span>                 :             :     }</span>
<span id="L201"><span class="lineNum">     201</span>                 :             : </span>
<span id="L202"><span class="lineNum">     202</span>                 :<span class="tlaGNC">        9107 :     if (params.isolationModeActive) {</span></span>
<span id="L203"><span class="lineNum">     203</span>                 :             :       // check that the asset being borrowed is borrowable in isolation mode AND</span>
<span id="L204"><span class="lineNum">     204</span>                 :             :       // the total exposure is no bigger than the collateral debt ceiling</span>
<span id="L205"><span class="lineNum">     205</span>                 :<span class="tlaGNC">          22 :       require(</span></span>
<span id="L206"><span class="lineNum">     206</span>                 :             :         params.reserveCache.reserveConfiguration.getBorrowableInIsolation(),</span>
<span id="L207"><span class="lineNum">     207</span>                 :             :         Errors.ASSET_NOT_BORROWABLE_IN_ISOLATION</span>
<span id="L208"><span class="lineNum">     208</span>                 :             :       );</span>
<span id="L209"><span class="lineNum">     209</span>                 :             : </span>
<span id="L210"><span class="lineNum">     210</span>                 :<span class="tlaGNC">          20 :       require(</span></span>
<span id="L211"><span class="lineNum">     211</span>                 :             :         reservesData[params.isolationModeCollateralAddress].isolationModeTotalDebt +</span>
<span id="L212"><span class="lineNum">     212</span>                 :             :           (params.amount /</span>
<span id="L213"><span class="lineNum">     213</span>                 :             :             10 ** (vars.reserveDecimals - ReserveConfiguration.DEBT_CEILING_DECIMALS))</span>
<span id="L214"><span class="lineNum">     214</span>                 :             :             .toUint128() &lt;=</span>
<span id="L215"><span class="lineNum">     215</span>                 :             :           params.isolationModeDebtCeiling,</span>
<span id="L216"><span class="lineNum">     216</span>                 :             :         Errors.DEBT_CEILING_EXCEEDED</span>
<span id="L217"><span class="lineNum">     217</span>                 :             :       );</span>
<span id="L218"><span class="lineNum">     218</span>                 :             :     }</span>
<span id="L219"><span class="lineNum">     219</span>                 :             : </span>
<span id="L220"><span class="lineNum">     220</span>                 :<span class="tlaGNC">       18208 :     if (params.userEModeCategory != 0) {</span></span>
<span id="L221"><span class="lineNum">     221</span>                 :<span class="tlaGNC">          14 :       require(</span></span>
<span id="L222"><span class="lineNum">     222</span>                 :             :         params.reserveCache.reserveConfiguration.getEModeCategory() == params.userEModeCategory,</span>
<span id="L223"><span class="lineNum">     223</span>                 :             :         Errors.INCONSISTENT_EMODE_CATEGORY</span>
<span id="L224"><span class="lineNum">     224</span>                 :             :       );</span>
<span id="L225"><span class="lineNum">     225</span>                 :<span class="tlaGNC">          12 :       vars.eModePriceSource = eModeCategories[params.userEModeCategory].priceSource;</span></span>
<span id="L226"><span class="lineNum">     226</span>                 :             :     }</span>
<span id="L227"><span class="lineNum">     227</span>                 :             : </span>
<span id="L228"><span class="lineNum">     228</span>                 :<span class="tlaGNC">       18206 :     (</span></span>
<span id="L229"><span class="lineNum">     229</span>                 :             :       vars.userCollateralInBaseCurrency,</span>
<span id="L230"><span class="lineNum">     230</span>                 :             :       vars.userDebtInBaseCurrency,</span>
<span id="L231"><span class="lineNum">     231</span>                 :             :       vars.currentLtv,</span>
<span id="L232"><span class="lineNum">     232</span>                 :             :       ,</span>
<span id="L233"><span class="lineNum">     233</span>                 :             :       vars.healthFactor,</span>
<span id="L234"><span class="lineNum">     234</span>                 :             : </span>
<span id="L235"><span class="lineNum">     235</span>                 :             :     ) = GenericLogic.calculateUserAccountData(</span>
<span id="L236"><span class="lineNum">     236</span>                 :             :       reservesData,</span>
<span id="L237"><span class="lineNum">     237</span>                 :             :       reservesList,</span>
<span id="L238"><span class="lineNum">     238</span>                 :             :       eModeCategories,</span>
<span id="L239"><span class="lineNum">     239</span>                 :             :       DataTypes.CalculateUserAccountDataParams({</span>
<span id="L240"><span class="lineNum">     240</span>                 :             :         userConfig: params.userConfig,</span>
<span id="L241"><span class="lineNum">     241</span>                 :             :         reservesCount: params.reservesCount,</span>
<span id="L242"><span class="lineNum">     242</span>                 :             :         user: params.userAddress,</span>
<span id="L243"><span class="lineNum">     243</span>                 :             :         oracle: params.oracle,</span>
<span id="L244"><span class="lineNum">     244</span>                 :             :         userEModeCategory: params.userEModeCategory</span>
<span id="L245"><span class="lineNum">     245</span>                 :             :       })</span>
<span id="L246"><span class="lineNum">     246</span>                 :             :     );</span>
<span id="L247"><span class="lineNum">     247</span>                 :             : </span>
<span id="L248"><span class="lineNum">     248</span>                 :<span class="tlaGNC">       18206 :     require(vars.userCollateralInBaseCurrency != 0, Errors.COLLATERAL_BALANCE_IS_ZERO);</span></span>
<span id="L249"><span class="lineNum">     249</span>                 :<span class="tlaGNC">       18204 :     require(vars.currentLtv != 0, Errors.LTV_VALIDATION_FAILED);</span></span>
<span id="L250"><span class="lineNum">     250</span>                 :             : </span>
<span id="L251"><span class="lineNum">     251</span>                 :<span class="tlaGNC">       18204 :     require(</span></span>
<span id="L252"><span class="lineNum">     252</span>                 :             :       vars.healthFactor &gt; HEALTH_FACTOR_LIQUIDATION_THRESHOLD,</span>
<span id="L253"><span class="lineNum">     253</span>                 :             :       Errors.HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD</span>
<span id="L254"><span class="lineNum">     254</span>                 :             :     );</span>
<span id="L255"><span class="lineNum">     255</span>                 :             : </span>
<span id="L256"><span class="lineNum">     256</span>                 :<span class="tlaGNC">       18202 :     vars.amountInBaseCurrency =</span></span>
<span id="L257"><span class="lineNum">     257</span>                 :             :       IPriceOracleGetter(params.oracle).getAssetPrice(</span>
<span id="L258"><span class="lineNum">     258</span>                 :             :         vars.eModePriceSource != address(0) ? vars.eModePriceSource : params.asset</span>
<span id="L259"><span class="lineNum">     259</span>                 :             :       ) *</span>
<span id="L260"><span class="lineNum">     260</span>                 :             :       params.amount;</span>
<span id="L261"><span class="lineNum">     261</span>                 :             :     unchecked {</span>
<span id="L262"><span class="lineNum">     262</span>                 :<span class="tlaGNC">       18202 :       vars.amountInBaseCurrency /= vars.assetUnit;</span></span>
<span id="L263"><span class="lineNum">     263</span>                 :             :     }</span>
<span id="L264"><span class="lineNum">     264</span>                 :             : </span>
<span id="L265"><span class="lineNum">     265</span>                 :             :     //add the current already borrowed amount to the amount requested to calculate the total collateral needed.</span>
<span id="L266"><span class="lineNum">     266</span>                 :<span class="tlaGNC">       18202 :     vars.collateralNeededInBaseCurrency = (vars.userDebtInBaseCurrency + vars.amountInBaseCurrency)</span></span>
<span id="L267"><span class="lineNum">     267</span>                 :             :       .percentDiv(vars.currentLtv); //LTV is calculated in percentage</span>
<span id="L268"><span class="lineNum">     268</span>                 :             : </span>
<span id="L269"><span class="lineNum">     269</span>                 :<span class="tlaGNC">       18202 :     require(</span></span>
<span id="L270"><span class="lineNum">     270</span>                 :             :       vars.collateralNeededInBaseCurrency &lt;= vars.userCollateralInBaseCurrency,</span>
<span id="L271"><span class="lineNum">     271</span>                 :             :       Errors.COLLATERAL_CANNOT_COVER_NEW_BORROW</span>
<span id="L272"><span class="lineNum">     272</span>                 :             :     );</span>
<span id="L273"><span class="lineNum">     273</span>                 :             : </span>
<span id="L274"><span class="lineNum">     274</span>                 :             :     /**</span>
<span id="L275"><span class="lineNum">     275</span>                 :             :      * Following conditions need to be met if the user is borrowing at a stable rate:</span>
<span id="L276"><span class="lineNum">     276</span>                 :             :      * 1. Reserve must be enabled for stable rate borrowing</span>
<span id="L277"><span class="lineNum">     277</span>                 :             :      * 2. Users cannot borrow from the reserve if their collateral is (mostly) the same currency</span>
<span id="L278"><span class="lineNum">     278</span>                 :             :      *    they are borrowing, to prevent abuses.</span>
<span id="L279"><span class="lineNum">     279</span>                 :             :      * 3. Users will be able to borrow only a portion of the total available liquidity</span>
<span id="L280"><span class="lineNum">     280</span>                 :             :      */</span>
<span id="L281"><span class="lineNum">     281</span>                 :             : </span>
<span id="L282"><span class="lineNum">     282</span>                 :<span class="tlaGNC">       18200 :     if (params.interestRateMode == DataTypes.InterestRateMode.STABLE) {</span></span>
<span id="L283"><span class="lineNum">     283</span>                 :             :       //check if the borrow mode is stable and if stable rate borrowing is enabled on this reserve</span>
<span id="L284"><span class="lineNum">     284</span>                 :             : </span>
<span id="L285"><span class="lineNum">     285</span>                 :<span class="tlaGNC">           8 :       require(vars.stableRateBorrowingEnabled, Errors.STABLE_BORROWING_NOT_ENABLED);</span></span>
<span id="L286"><span class="lineNum">     286</span>                 :             : </span>
<span id="L287"><span class="lineNum">     287</span>                 :<span class="tlaGNC">           6 :       require(</span></span>
<span id="L288"><span class="lineNum">     288</span>                 :             :         !params.userConfig.isUsingAsCollateral(reservesData[params.asset].id) ||</span>
<span id="L289"><span class="lineNum">     289</span>                 :             :           params.reserveCache.reserveConfiguration.getLtv() == 0 ||</span>
<span id="L290"><span class="lineNum">     290</span>                 :             :           params.amount &gt; IERC20(params.reserveCache.aTokenAddress).balanceOf(params.userAddress),</span>
<span id="L291"><span class="lineNum">     291</span>                 :             :         Errors.COLLATERAL_SAME_AS_BORROWING_CURRENCY</span>
<span id="L292"><span class="lineNum">     292</span>                 :             :       );</span>
<span id="L293"><span class="lineNum">     293</span>                 :             : </span>
<span id="L294"><span class="lineNum">     294</span>                 :<span class="tlaGNC">           4 :       vars.availableLiquidity = reservesData[params.asset].virtualUnderlyingBalance;</span></span>
<span id="L295"><span class="lineNum">     295</span>                 :             : </span>
<span id="L296"><span class="lineNum">     296</span>                 :             :       //calculate the max available loan size in stable rate mode as a percentage of the</span>
<span id="L297"><span class="lineNum">     297</span>                 :             :       //available liquidity</span>
<span id="L298"><span class="lineNum">     298</span>                 :<span class="tlaGNC">           6 :       uint256 maxLoanSizeStable = vars.availableLiquidity.percentMul(params.maxStableLoanPercent);</span></span>
<span id="L299"><span class="lineNum">     299</span>                 :             : </span>
<span id="L300"><span class="lineNum">     300</span>                 :<span class="tlaGNC">           4 :       require(params.amount &lt;= maxLoanSizeStable, Errors.AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE);</span></span>
<span id="L301"><span class="lineNum">     301</span>                 :             :     }</span>
<span id="L302"><span class="lineNum">     302</span>                 :             : </span>
<span id="L303"><span class="lineNum">     303</span>                 :<span class="tlaGNC">       18194 :     if (params.userConfig.isBorrowingAny()) {</span></span>
<span id="L304"><span class="lineNum">     304</span>                 :<span class="tlaGNC">          14 :       (vars.siloedBorrowingEnabled, vars.siloedBorrowingAddress) = params</span></span>
<span id="L305"><span class="lineNum">     305</span>                 :             :         .userConfig</span>
<span id="L306"><span class="lineNum">     306</span>                 :             :         .getSiloedBorrowingState(reservesData, reservesList);</span>
<span id="L307"><span class="lineNum">     307</span>                 :             : </span>
<span id="L308"><span class="lineNum">     308</span>                 :<span class="tlaGNC">           7 :       if (vars.siloedBorrowingEnabled) {</span></span>
<span id="L309"><span class="lineNum">     309</span>                 :<span class="tlaGNC">           2 :         require(vars.siloedBorrowingAddress == params.asset, Errors.SILOED_BORROWING_VIOLATION);</span></span>
<span id="L310"><span class="lineNum">     310</span>                 :             :       } else {</span>
<span id="L311"><span class="lineNum">     311</span>                 :<span class="tlaGNC">          12 :         require(</span></span>
<span id="L312"><span class="lineNum">     312</span>                 :             :           !params.reserveCache.reserveConfiguration.getSiloedBorrowing(),</span>
<span id="L313"><span class="lineNum">     313</span>                 :             :           Errors.SILOED_BORROWING_VIOLATION</span>
<span id="L314"><span class="lineNum">     314</span>                 :             :         );</span>
<span id="L315"><span class="lineNum">     315</span>                 :             :       }</span>
<span id="L316"><span class="lineNum">     316</span>                 :             :     }</span>
<span id="L317"><span class="lineNum">     317</span>                 :             :   }</span>
<span id="L318"><span class="lineNum">     318</span>                 :             : </span>
<span id="L319"><span class="lineNum">     319</span>                 :             :   /**</span>
<span id="L320"><span class="lineNum">     320</span>                 :             :    * @notice Validates a repay action.</span>
<span id="L321"><span class="lineNum">     321</span>                 :             :    * @param reserveCache The cached data of the reserve</span>
<span id="L322"><span class="lineNum">     322</span>                 :             :    * @param amountSent The amount sent for the repayment. Can be an actual value or uint(-1)</span>
<span id="L323"><span class="lineNum">     323</span>                 :             :    * @param interestRateMode The interest rate mode of the debt being repaid</span>
<span id="L324"><span class="lineNum">     324</span>                 :             :    * @param onBehalfOf The address of the user msg.sender is repaying for</span>
<span id="L325"><span class="lineNum">     325</span>                 :             :    * @param stableDebt The borrow balance of the user</span>
<span id="L326"><span class="lineNum">     326</span>                 :             :    * @param variableDebt The borrow balance of the user</span>
<span id="L327"><span class="lineNum">     327</span>                 :             :    */</span>
<span id="L328"><span class="lineNum">     328</span>                 :<span class="tlaGNC">        5029 :   function validateRepay(</span></span>
<span id="L329"><span class="lineNum">     329</span>                 :             :     DataTypes.ReserveCache memory reserveCache,</span>
<span id="L330"><span class="lineNum">     330</span>                 :             :     uint256 amountSent,</span>
<span id="L331"><span class="lineNum">     331</span>                 :             :     DataTypes.InterestRateMode interestRateMode,</span>
<span id="L332"><span class="lineNum">     332</span>                 :             :     address onBehalfOf,</span>
<span id="L333"><span class="lineNum">     333</span>                 :             :     uint256 stableDebt,</span>
<span id="L334"><span class="lineNum">     334</span>                 :             :     uint256 variableDebt</span>
<span id="L335"><span class="lineNum">     335</span>                 :             :   ) internal view {</span>
<span id="L336"><span class="lineNum">     336</span>                 :<span class="tlaGNC">       10058 :     require(amountSent != 0, Errors.INVALID_AMOUNT);</span></span>
<span id="L337"><span class="lineNum">     337</span>                 :<span class="tlaGNC">       10056 :     require(</span></span>
<span id="L338"><span class="lineNum">     338</span>                 :             :       amountSent != type(uint256).max || msg.sender == onBehalfOf,</span>
<span id="L339"><span class="lineNum">     339</span>                 :             :       Errors.NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF</span>
<span id="L340"><span class="lineNum">     340</span>                 :             :     );</span>
<span id="L341"><span class="lineNum">     341</span>                 :             : </span>
<span id="L342"><span class="lineNum">     342</span>                 :<span class="tlaGNC">       15081 :     (bool isActive, , , , bool isPaused) = reserveCache.reserveConfiguration.getFlags();</span></span>
<span id="L343"><span class="lineNum">     343</span>                 :<span class="tlaGNC">       10054 :     require(isActive, Errors.RESERVE_INACTIVE);</span></span>
<span id="L344"><span class="lineNum">     344</span>                 :<span class="tlaGNC">       10052 :     require(!isPaused, Errors.RESERVE_PAUSED);</span></span>
<span id="L345"><span class="lineNum">     345</span>                 :             : </span>
<span id="L346"><span class="lineNum">     346</span>                 :<span class="tlaGNC">       10050 :     require(</span></span>
<span id="L347"><span class="lineNum">     347</span>                 :             :       (stableDebt != 0 &amp;&amp; interestRateMode == DataTypes.InterestRateMode.STABLE) ||</span>
<span id="L348"><span class="lineNum">     348</span>                 :             :         (variableDebt != 0 &amp;&amp; interestRateMode == DataTypes.InterestRateMode.VARIABLE),</span>
<span id="L349"><span class="lineNum">     349</span>                 :             :       Errors.NO_DEBT_OF_SELECTED_TYPE</span>
<span id="L350"><span class="lineNum">     350</span>                 :             :     );</span>
<span id="L351"><span class="lineNum">     351</span>                 :             :   }</span>
<span id="L352"><span class="lineNum">     352</span>                 :             : </span>
<span id="L353"><span class="lineNum">     353</span>                 :             :   /**</span>
<span id="L354"><span class="lineNum">     354</span>                 :             :    * @notice Validates a swap of borrow rate mode.</span>
<span id="L355"><span class="lineNum">     355</span>                 :             :    * @param reserve The reserve state on which the user is swapping the rate</span>
<span id="L356"><span class="lineNum">     356</span>                 :             :    * @param reserveCache The cached data of the reserve</span>
<span id="L357"><span class="lineNum">     357</span>                 :             :    * @param userConfig The user reserves configuration</span>
<span id="L358"><span class="lineNum">     358</span>                 :             :    * @param stableDebt The stable debt of the user</span>
<span id="L359"><span class="lineNum">     359</span>                 :             :    * @param variableDebt The variable debt of the user</span>
<span id="L360"><span class="lineNum">     360</span>                 :             :    * @param currentRateMode The rate mode of the debt being swapped</span>
<span id="L361"><span class="lineNum">     361</span>                 :             :    */</span>
<span id="L362"><span class="lineNum">     362</span>                 :<span class="tlaGNC">           8 :   function validateSwapRateMode(</span></span>
<span id="L363"><span class="lineNum">     363</span>                 :             :     DataTypes.ReserveData storage reserve,</span>
<span id="L364"><span class="lineNum">     364</span>                 :             :     DataTypes.ReserveCache memory reserveCache,</span>
<span id="L365"><span class="lineNum">     365</span>                 :             :     DataTypes.UserConfigurationMap storage userConfig,</span>
<span id="L366"><span class="lineNum">     366</span>                 :             :     uint256 stableDebt,</span>
<span id="L367"><span class="lineNum">     367</span>                 :             :     uint256 variableDebt,</span>
<span id="L368"><span class="lineNum">     368</span>                 :             :     DataTypes.InterestRateMode currentRateMode</span>
<span id="L369"><span class="lineNum">     369</span>                 :             :   ) internal view {</span>
<span id="L370"><span class="lineNum">     370</span>                 :<span class="tlaGNC">          24 :     (bool isActive, , , bool stableRateEnabled, bool isPaused) = reserveCache</span></span>
<span id="L371"><span class="lineNum">     371</span>                 :             :       .reserveConfiguration</span>
<span id="L372"><span class="lineNum">     372</span>                 :             :       .getFlags();</span>
<span id="L373"><span class="lineNum">     373</span>                 :<span class="tlaGNC">          16 :     require(isActive, Errors.RESERVE_INACTIVE);</span></span>
<span id="L374"><span class="lineNum">     374</span>                 :<span class="tlaGNC">          14 :     require(!isPaused, Errors.RESERVE_PAUSED);</span></span>
<span id="L375"><span class="lineNum">     375</span>                 :             : </span>
<span id="L376"><span class="lineNum">     376</span>                 :<span class="tlaGNC">          12 :     if (currentRateMode == DataTypes.InterestRateMode.STABLE) {</span></span>
<span id="L377"><span class="lineNum">     377</span>                 :<span class="tlaGNC">           2 :       require(stableDebt != 0, Errors.NO_OUTSTANDING_STABLE_DEBT);</span></span>
<span id="L378"><span class="lineNum">     378</span>                 :<span class="tlaGNC">          10 :     } else if (currentRateMode == DataTypes.InterestRateMode.VARIABLE) {</span></span>
<span id="L379"><span class="lineNum">     379</span>                 :<span class="tlaGNC">           8 :       require(variableDebt != 0, Errors.NO_OUTSTANDING_VARIABLE_DEBT);</span></span>
<span id="L380"><span class="lineNum">     380</span>                 :             :       /**</span>
<span id="L381"><span class="lineNum">     381</span>                 :             :        * user wants to swap to stable, before swapping we need to ensure that</span>
<span id="L382"><span class="lineNum">     382</span>                 :             :        * 1. stable borrow rate is enabled on the reserve</span>
<span id="L383"><span class="lineNum">     383</span>                 :             :        * 2. user is not trying to abuse the reserve by supplying</span>
<span id="L384"><span class="lineNum">     384</span>                 :             :        * more collateral than he is borrowing, artificially lowering</span>
<span id="L385"><span class="lineNum">     385</span>                 :             :        * the interest rate, borrowing at variable, and switching to stable</span>
<span id="L386"><span class="lineNum">     386</span>                 :             :        */</span>
<span id="L387"><span class="lineNum">     387</span>                 :<span class="tlaGNC">           6 :       require(stableRateEnabled, Errors.STABLE_BORROWING_NOT_ENABLED);</span></span>
<span id="L388"><span class="lineNum">     388</span>                 :             : </span>
<span id="L389"><span class="lineNum">     389</span>                 :<span class="tlaGNC">           6 :       require(</span></span>
<span id="L390"><span class="lineNum">     390</span>                 :             :         !userConfig.isUsingAsCollateral(reserve.id) ||</span>
<span id="L391"><span class="lineNum">     391</span>                 :             :           reserveCache.reserveConfiguration.getLtv() == 0 ||</span>
<span id="L392"><span class="lineNum">     392</span>                 :             :           stableDebt + variableDebt &gt; IERC20(reserveCache.aTokenAddress).balanceOf(msg.sender),</span>
<span id="L393"><span class="lineNum">     393</span>                 :             :         Errors.COLLATERAL_SAME_AS_BORROWING_CURRENCY</span>
<span id="L394"><span class="lineNum">     394</span>                 :             :       );</span>
<span id="L395"><span class="lineNum">     395</span>                 :             :     } else {</span>
<span id="L396"><span class="lineNum">     396</span>                 :<span class="tlaGNC">           2 :       revert(Errors.INVALID_INTEREST_RATE_MODE_SELECTED);</span></span>
<span id="L397"><span class="lineNum">     397</span>                 :             :     }</span>
<span id="L398"><span class="lineNum">     398</span>                 :             :   }</span>
<span id="L399"><span class="lineNum">     399</span>                 :             : </span>
<span id="L400"><span class="lineNum">     400</span>                 :             :   /**</span>
<span id="L401"><span class="lineNum">     401</span>                 :             :    * @notice Validates a stable borrow rate rebalance action.</span>
<span id="L402"><span class="lineNum">     402</span>                 :             :    * @dev Rebalancing is accepted when depositors are earning &lt;= 90% of their earnings in pure supply/demand market (variable rate only)</span>
<span id="L403"><span class="lineNum">     403</span>                 :             :    * For this to be the case, there has to be quite large stable debt with an interest rate below the current variable rate.</span>
<span id="L404"><span class="lineNum">     404</span>                 :             :    * @param reserve The reserve state on which the user is getting rebalanced</span>
<span id="L405"><span class="lineNum">     405</span>                 :             :    * @param reserveCache The cached state of the reserve</span>
<span id="L406"><span class="lineNum">     406</span>                 :             :    * @param reserveAddress The address of the reserve</span>
<span id="L407"><span class="lineNum">     407</span>                 :             :    */</span>
<span id="L408"><span class="lineNum">     408</span>                 :<span class="tlaGNC">           5 :   function validateRebalanceStableBorrowRate(</span></span>
<span id="L409"><span class="lineNum">     409</span>                 :             :     DataTypes.ReserveData storage reserve,</span>
<span id="L410"><span class="lineNum">     410</span>                 :             :     DataTypes.ReserveCache memory reserveCache,</span>
<span id="L411"><span class="lineNum">     411</span>                 :             :     address reserveAddress</span>
<span id="L412"><span class="lineNum">     412</span>                 :             :   ) internal view {</span>
<span id="L413"><span class="lineNum">     413</span>                 :<span class="tlaGNC">          15 :     (bool isActive, , , , bool isPaused) = reserveCache.reserveConfiguration.getFlags();</span></span>
<span id="L414"><span class="lineNum">     414</span>                 :<span class="tlaGNC">          10 :     require(isActive, Errors.RESERVE_INACTIVE);</span></span>
<span id="L415"><span class="lineNum">     415</span>                 :<span class="tlaGNC">           8 :     require(!isPaused, Errors.RESERVE_PAUSED);</span></span>
<span id="L416"><span class="lineNum">     416</span>                 :             : </span>
<span id="L417"><span class="lineNum">     417</span>                 :<span class="tlaGNC">          12 :     uint256 totalDebt = IERC20(reserveCache.stableDebtTokenAddress).totalSupply() +</span></span>
<span id="L418"><span class="lineNum">     418</span>                 :<span class="tlaGNC">           6 :       IERC20(reserveCache.variableDebtTokenAddress).totalSupply();</span></span>
<span id="L419"><span class="lineNum">     419</span>                 :             : </span>
<span id="L420"><span class="lineNum">     420</span>                 :<span class="tlaGNC">           9 :     (uint256 liquidityRateVariableDebtOnly, , ) = IReserveInterestRateStrategy(</span></span>
<span id="L421"><span class="lineNum">     421</span>                 :             :       reserve.interestRateStrategyAddress</span>
<span id="L422"><span class="lineNum">     422</span>                 :             :     ).calculateInterestRates(</span>
<span id="L423"><span class="lineNum">     423</span>                 :             :         DataTypes.CalculateInterestRatesParams({</span>
<span id="L424"><span class="lineNum">     424</span>                 :             :           unbacked: reserve.unbacked,</span>
<span id="L425"><span class="lineNum">     425</span>                 :             :           liquidityAdded: 0,</span>
<span id="L426"><span class="lineNum">     426</span>                 :             :           liquidityTaken: 0,</span>
<span id="L427"><span class="lineNum">     427</span>                 :             :           totalStableDebt: 0,</span>
<span id="L428"><span class="lineNum">     428</span>                 :             :           totalVariableDebt: totalDebt,</span>
<span id="L429"><span class="lineNum">     429</span>                 :             :           averageStableBorrowRate: 0,</span>
<span id="L430"><span class="lineNum">     430</span>                 :             :           reserveFactor: reserveCache.reserveFactor,</span>
<span id="L431"><span class="lineNum">     431</span>                 :             :           reserve: reserveAddress,</span>
<span id="L432"><span class="lineNum">     432</span>                 :             :           usingVirtualBalance: reserve.configuration.getIsVirtualAccActive(),</span>
<span id="L433"><span class="lineNum">     433</span>                 :             :           virtualUnderlyingBalance: reserve.virtualUnderlyingBalance</span>
<span id="L434"><span class="lineNum">     434</span>                 :             :         })</span>
<span id="L435"><span class="lineNum">     435</span>                 :             :       );</span>
<span id="L436"><span class="lineNum">     436</span>                 :             : </span>
<span id="L437"><span class="lineNum">     437</span>                 :<span class="tlaGNC">           6 :     require(</span></span>
<span id="L438"><span class="lineNum">     438</span>                 :             :       reserveCache.currLiquidityRate &lt;=</span>
<span id="L439"><span class="lineNum">     439</span>                 :             :         liquidityRateVariableDebtOnly.percentMul(REBALANCE_UP_LIQUIDITY_RATE_THRESHOLD),</span>
<span id="L440"><span class="lineNum">     440</span>                 :             :       Errors.INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET</span>
<span id="L441"><span class="lineNum">     441</span>                 :             :     );</span>
<span id="L442"><span class="lineNum">     442</span>                 :             :   }</span>
<span id="L443"><span class="lineNum">     443</span>                 :             : </span>
<span id="L444"><span class="lineNum">     444</span>                 :             :   /**</span>
<span id="L445"><span class="lineNum">     445</span>                 :             :    * @notice Validates the action of setting an asset as collateral.</span>
<span id="L446"><span class="lineNum">     446</span>                 :             :    * @param reserveCache The cached data of the reserve</span>
<span id="L447"><span class="lineNum">     447</span>                 :             :    * @param userBalance The balance of the user</span>
<span id="L448"><span class="lineNum">     448</span>                 :             :    */</span>
<span id="L449"><span class="lineNum">     449</span>                 :<span class="tlaGNC">          43 :   function validateSetUseReserveAsCollateral(</span></span>
<span id="L450"><span class="lineNum">     450</span>                 :             :     DataTypes.ReserveCache memory reserveCache,</span>
<span id="L451"><span class="lineNum">     451</span>                 :             :     uint256 userBalance</span>
<span id="L452"><span class="lineNum">     452</span>                 :             :   ) internal pure {</span>
<span id="L453"><span class="lineNum">     453</span>                 :<span class="tlaGNC">          86 :     require(userBalance != 0, Errors.UNDERLYING_BALANCE_ZERO);</span></span>
<span id="L454"><span class="lineNum">     454</span>                 :             : </span>
<span id="L455"><span class="lineNum">     455</span>                 :<span class="tlaGNC">         123 :     (bool isActive, , , , bool isPaused) = reserveCache.reserveConfiguration.getFlags();</span></span>
<span id="L456"><span class="lineNum">     456</span>                 :<span class="tlaGNC">          82 :     require(isActive, Errors.RESERVE_INACTIVE);</span></span>
<span id="L457"><span class="lineNum">     457</span>                 :<span class="tlaGNC">          78 :     require(!isPaused, Errors.RESERVE_PAUSED);</span></span>
<span id="L458"><span class="lineNum">     458</span>                 :             :   }</span>
<span id="L459"><span class="lineNum">     459</span>                 :             : </span>
<span id="L460"><span class="lineNum">     460</span>                 :             :   /**</span>
<span id="L461"><span class="lineNum">     461</span>                 :             :    * @notice Validates a flashloan action.</span>
<span id="L462"><span class="lineNum">     462</span>                 :             :    * @param reservesData The state of all the reserves</span>
<span id="L463"><span class="lineNum">     463</span>                 :             :    * @param assets The assets being flash-borrowed</span>
<span id="L464"><span class="lineNum">     464</span>                 :             :    * @param amounts The amounts for each asset being borrowed</span>
<span id="L465"><span class="lineNum">     465</span>                 :             :    */</span>
<span id="L466"><span class="lineNum">     466</span>                 :<span class="tlaGNC">          10 :   function validateFlashloan(</span></span>
<span id="L467"><span class="lineNum">     467</span>                 :             :     mapping(address =&gt; DataTypes.ReserveData) storage reservesData,</span>
<span id="L468"><span class="lineNum">     468</span>                 :             :     address[] memory assets,</span>
<span id="L469"><span class="lineNum">     469</span>                 :             :     uint256[] memory amounts</span>
<span id="L470"><span class="lineNum">     470</span>                 :             :   ) internal view {</span>
<span id="L471"><span class="lineNum">     471</span>                 :<span class="tlaGNC">          20 :     require(assets.length == amounts.length, Errors.INCONSISTENT_FLASHLOAN_PARAMS);</span></span>
<span id="L472"><span class="lineNum">     472</span>                 :<span class="tlaGNC">          44 :     for (uint256 i = 0; i &lt; assets.length; i++) {</span></span>
<span id="L473"><span class="lineNum">     473</span>                 :<span class="tlaGNC">          22 :       validateFlashloanSimple(reservesData[assets[i]], amounts[i]);</span></span>
<span id="L474"><span class="lineNum">     474</span>                 :             :     }</span>
<span id="L475"><span class="lineNum">     475</span>                 :             :   }</span>
<span id="L476"><span class="lineNum">     476</span>                 :             : </span>
<span id="L477"><span class="lineNum">     477</span>                 :             :   /**</span>
<span id="L478"><span class="lineNum">     478</span>                 :             :    * @notice Validates a flashloan action.</span>
<span id="L479"><span class="lineNum">     479</span>                 :             :    * @param reserve The state of the reserve</span>
<span id="L480"><span class="lineNum">     480</span>                 :             :    */</span>
<span id="L481"><span class="lineNum">     481</span>                 :<span class="tlaGNC">          21 :   function validateFlashloanSimple(</span></span>
<span id="L482"><span class="lineNum">     482</span>                 :             :     DataTypes.ReserveData storage reserve,</span>
<span id="L483"><span class="lineNum">     483</span>                 :             :     uint256 amount</span>
<span id="L484"><span class="lineNum">     484</span>                 :             :   ) internal view {</span>
<span id="L485"><span class="lineNum">     485</span>                 :<span class="tlaGNC">          42 :     DataTypes.ReserveConfigurationMap memory configuration = reserve.configuration;</span></span>
<span id="L486"><span class="lineNum">     486</span>                 :<span class="tlaGNC">          42 :     require(!configuration.getPaused(), Errors.RESERVE_PAUSED);</span></span>
<span id="L487"><span class="lineNum">     487</span>                 :<span class="tlaGNC">          40 :     require(configuration.getActive(), Errors.RESERVE_INACTIVE);</span></span>
<span id="L488"><span class="lineNum">     488</span>                 :<span class="tlaGNC">          38 :     require(configuration.getFlashLoanEnabled(), Errors.FLASHLOAN_DISABLED);</span></span>
<span id="L489"><span class="lineNum">     489</span>                 :<span class="tlaGNC">          36 :     require(IERC20(reserve.aTokenAddress).totalSupply() &gt;= amount, Errors.INVALID_AMOUNT);</span></span>
<span id="L490"><span class="lineNum">     490</span>                 :             :   }</span>
<span id="L491"><span class="lineNum">     491</span>                 :             : </span>
<span id="L492"><span class="lineNum">     492</span>                 :             :   struct ValidateLiquidationCallLocalVars {</span>
<span id="L493"><span class="lineNum">     493</span>                 :             :     bool collateralReserveActive;</span>
<span id="L494"><span class="lineNum">     494</span>                 :             :     bool collateralReservePaused;</span>
<span id="L495"><span class="lineNum">     495</span>                 :             :     bool principalReserveActive;</span>
<span id="L496"><span class="lineNum">     496</span>                 :             :     bool principalReservePaused;</span>
<span id="L497"><span class="lineNum">     497</span>                 :             :     bool isCollateralEnabled;</span>
<span id="L498"><span class="lineNum">     498</span>                 :             :   }</span>
<span id="L499"><span class="lineNum">     499</span>                 :             : </span>
<span id="L500"><span class="lineNum">     500</span>                 :             :   /**</span>
<span id="L501"><span class="lineNum">     501</span>                 :             :    * @notice Validates the liquidation action.</span>
<span id="L502"><span class="lineNum">     502</span>                 :             :    * @param userConfig The user configuration mapping</span>
<span id="L503"><span class="lineNum">     503</span>                 :             :    * @param collateralReserve The reserve data of the collateral</span>
<span id="L504"><span class="lineNum">     504</span>                 :             :    * @param debtReserve The reserve data of the debt</span>
<span id="L505"><span class="lineNum">     505</span>                 :             :    * @param params Additional parameters needed for the validation</span>
<span id="L506"><span class="lineNum">     506</span>                 :             :    */</span>
<span id="L507"><span class="lineNum">     507</span>                 :<span class="tlaGNC">       11292 :   function validateLiquidationCall(</span></span>
<span id="L508"><span class="lineNum">     508</span>                 :             :     DataTypes.UserConfigurationMap storage userConfig,</span>
<span id="L509"><span class="lineNum">     509</span>                 :             :     DataTypes.ReserveData storage collateralReserve,</span>
<span id="L510"><span class="lineNum">     510</span>                 :             :     DataTypes.ReserveData storage debtReserve,</span>
<span id="L511"><span class="lineNum">     511</span>                 :             :     DataTypes.ValidateLiquidationCallParams memory params</span>
<span id="L512"><span class="lineNum">     512</span>                 :             :   ) internal view {</span>
<span id="L513"><span class="lineNum">     513</span>                 :<span class="tlaGNC">       22584 :     ValidateLiquidationCallLocalVars memory vars;</span></span>
<span id="L514"><span class="lineNum">     514</span>                 :             : </span>
<span id="L515"><span class="lineNum">     515</span>                 :<span class="tlaGNC">       22584 :     (vars.collateralReserveActive, , , , vars.collateralReservePaused) = collateralReserve</span></span>
<span id="L516"><span class="lineNum">     516</span>                 :             :       .configuration</span>
<span id="L517"><span class="lineNum">     517</span>                 :             :       .getFlags();</span>
<span id="L518"><span class="lineNum">     518</span>                 :             : </span>
<span id="L519"><span class="lineNum">     519</span>                 :<span class="tlaGNC">       22584 :     (vars.principalReserveActive, , , , vars.principalReservePaused) = params</span></span>
<span id="L520"><span class="lineNum">     520</span>                 :             :       .debtReserveCache</span>
<span id="L521"><span class="lineNum">     521</span>                 :             :       .reserveConfiguration</span>
<span id="L522"><span class="lineNum">     522</span>                 :             :       .getFlags();</span>
<span id="L523"><span class="lineNum">     523</span>                 :             : </span>
<span id="L524"><span class="lineNum">     524</span>                 :<span class="tlaGNC">       22584 :     require(vars.collateralReserveActive &amp;&amp; vars.principalReserveActive, Errors.RESERVE_INACTIVE);</span></span>
<span id="L525"><span class="lineNum">     525</span>                 :<span class="tlaGNC">       22582 :     require(!vars.collateralReservePaused &amp;&amp; !vars.principalReservePaused, Errors.RESERVE_PAUSED);</span></span>
<span id="L526"><span class="lineNum">     526</span>                 :             : </span>
<span id="L527"><span class="lineNum">     527</span>                 :<span class="tlaGNC">       22580 :     require(</span></span>
<span id="L528"><span class="lineNum">     528</span>                 :             :       params.priceOracleSentinel == address(0) ||</span>
<span id="L529"><span class="lineNum">     529</span>                 :             :         params.healthFactor &lt; MINIMUM_HEALTH_FACTOR_LIQUIDATION_THRESHOLD ||</span>
<span id="L530"><span class="lineNum">     530</span>                 :             :         IPriceOracleSentinel(params.priceOracleSentinel).isLiquidationAllowed(),</span>
<span id="L531"><span class="lineNum">     531</span>                 :             :       Errors.PRICE_ORACLE_SENTINEL_CHECK_FAILED</span>
<span id="L532"><span class="lineNum">     532</span>                 :             :     );</span>
<span id="L533"><span class="lineNum">     533</span>                 :             : </span>
<span id="L534"><span class="lineNum">     534</span>                 :<span class="tlaGNC">       22578 :     require(</span></span>
<span id="L535"><span class="lineNum">     535</span>                 :             :       collateralReserve.liquidationGracePeriodUntil &lt; uint40(block.timestamp) &amp;&amp;</span>
<span id="L536"><span class="lineNum">     536</span>                 :             :         debtReserve.liquidationGracePeriodUntil &lt; uint40(block.timestamp),</span>
<span id="L537"><span class="lineNum">     537</span>                 :             :       Errors.LIQUIDATION_GRACE_SENTINEL_CHECK_FAILED</span>
<span id="L538"><span class="lineNum">     538</span>                 :             :     );</span>
<span id="L539"><span class="lineNum">     539</span>                 :             : </span>
<span id="L540"><span class="lineNum">     540</span>                 :<span class="tlaGNC">       12030 :     require(</span></span>
<span id="L541"><span class="lineNum">     541</span>                 :             :       params.healthFactor &lt; HEALTH_FACTOR_LIQUIDATION_THRESHOLD,</span>
<span id="L542"><span class="lineNum">     542</span>                 :             :       Errors.HEALTH_FACTOR_NOT_BELOW_THRESHOLD</span>
<span id="L543"><span class="lineNum">     543</span>                 :             :     );</span>
<span id="L544"><span class="lineNum">     544</span>                 :             : </span>
<span id="L545"><span class="lineNum">     545</span>                 :<span class="tlaGNC">       12028 :     vars.isCollateralEnabled =</span></span>
<span id="L546"><span class="lineNum">     546</span>                 :             :       collateralReserve.configuration.getLiquidationThreshold() != 0 &amp;&amp;</span>
<span id="L547"><span class="lineNum">     547</span>                 :             :       userConfig.isUsingAsCollateral(collateralReserve.id);</span>
<span id="L548"><span class="lineNum">     548</span>                 :             : </span>
<span id="L549"><span class="lineNum">     549</span>                 :             :     //if collateral isn't enabled as collateral by user, it cannot be liquidated</span>
<span id="L550"><span class="lineNum">     550</span>                 :<span class="tlaGNC">       12028 :     require(vars.isCollateralEnabled, Errors.COLLATERAL_CANNOT_BE_LIQUIDATED);</span></span>
<span id="L551"><span class="lineNum">     551</span>                 :<span class="tlaGNC">       12026 :     require(params.totalDebt != 0, Errors.SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER);</span></span>
<span id="L552"><span class="lineNum">     552</span>                 :             :   }</span>
<span id="L553"><span class="lineNum">     553</span>                 :             : </span>
<span id="L554"><span class="lineNum">     554</span>                 :             :   /**</span>
<span id="L555"><span class="lineNum">     555</span>                 :             :    * @notice Validates the health factor of a user.</span>
<span id="L556"><span class="lineNum">     556</span>                 :             :    * @param reservesData The state of all the reserves</span>
<span id="L557"><span class="lineNum">     557</span>                 :             :    * @param reservesList The addresses of all the active reserves</span>
<span id="L558"><span class="lineNum">     558</span>                 :             :    * @param eModeCategories The configuration of all the efficiency mode categories</span>
<span id="L559"><span class="lineNum">     559</span>                 :             :    * @param userConfig The state of the user for the specific reserve</span>
<span id="L560"><span class="lineNum">     560</span>                 :             :    * @param user The user to validate health factor of</span>
<span id="L561"><span class="lineNum">     561</span>                 :             :    * @param userEModeCategory The users active efficiency mode category</span>
<span id="L562"><span class="lineNum">     562</span>                 :             :    * @param reservesCount The number of available reserves</span>
<span id="L563"><span class="lineNum">     563</span>                 :             :    * @param oracle The price oracle</span>
<span id="L564"><span class="lineNum">     564</span>                 :             :    */</span>
<span id="L565"><span class="lineNum">     565</span>                 :<span class="tlaGNC">          27 :   function validateHealthFactor(</span></span>
<span id="L566"><span class="lineNum">     566</span>                 :             :     mapping(address =&gt; DataTypes.ReserveData) storage reservesData,</span>
<span id="L567"><span class="lineNum">     567</span>                 :             :     mapping(uint256 =&gt; address) storage reservesList,</span>
<span id="L568"><span class="lineNum">     568</span>                 :             :     mapping(uint8 =&gt; DataTypes.EModeCategory) storage eModeCategories,</span>
<span id="L569"><span class="lineNum">     569</span>                 :             :     DataTypes.UserConfigurationMap memory userConfig,</span>
<span id="L570"><span class="lineNum">     570</span>                 :             :     address user,</span>
<span id="L571"><span class="lineNum">     571</span>                 :             :     uint8 userEModeCategory,</span>
<span id="L572"><span class="lineNum">     572</span>                 :             :     uint256 reservesCount,</span>
<span id="L573"><span class="lineNum">     573</span>                 :             :     address oracle</span>
<span id="L574"><span class="lineNum">     574</span>                 :             :   ) internal view returns (uint256, bool) {</span>
<span id="L575"><span class="lineNum">     575</span>                 :<span class="tlaGNC">          81 :     (, , , , uint256 healthFactor, bool hasZeroLtvCollateral) = GenericLogic</span></span>
<span id="L576"><span class="lineNum">     576</span>                 :             :       .calculateUserAccountData(</span>
<span id="L577"><span class="lineNum">     577</span>                 :             :         reservesData,</span>
<span id="L578"><span class="lineNum">     578</span>                 :             :         reservesList,</span>
<span id="L579"><span class="lineNum">     579</span>                 :             :         eModeCategories,</span>
<span id="L580"><span class="lineNum">     580</span>                 :             :         DataTypes.CalculateUserAccountDataParams({</span>
<span id="L581"><span class="lineNum">     581</span>                 :             :           userConfig: userConfig,</span>
<span id="L582"><span class="lineNum">     582</span>                 :             :           reservesCount: reservesCount,</span>
<span id="L583"><span class="lineNum">     583</span>                 :             :           user: user,</span>
<span id="L584"><span class="lineNum">     584</span>                 :             :           oracle: oracle,</span>
<span id="L585"><span class="lineNum">     585</span>                 :             :           userEModeCategory: userEModeCategory</span>
<span id="L586"><span class="lineNum">     586</span>                 :             :         })</span>
<span id="L587"><span class="lineNum">     587</span>                 :             :       );</span>
<span id="L588"><span class="lineNum">     588</span>                 :             : </span>
<span id="L589"><span class="lineNum">     589</span>                 :<span class="tlaGNC">          54 :     require(</span></span>
<span id="L590"><span class="lineNum">     590</span>                 :             :       healthFactor &gt;= HEALTH_FACTOR_LIQUIDATION_THRESHOLD,</span>
<span id="L591"><span class="lineNum">     591</span>                 :             :       Errors.HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD</span>
<span id="L592"><span class="lineNum">     592</span>                 :             :     );</span>
<span id="L593"><span class="lineNum">     593</span>                 :             : </span>
<span id="L594"><span class="lineNum">     594</span>                 :<span class="tlaGNC">          42 :     return (healthFactor, hasZeroLtvCollateral);</span></span>
<span id="L595"><span class="lineNum">     595</span>                 :             :   }</span>
<span id="L596"><span class="lineNum">     596</span>                 :             : </span>
<span id="L597"><span class="lineNum">     597</span>                 :             :   /**</span>
<span id="L598"><span class="lineNum">     598</span>                 :             :    * @notice Validates the health factor of a user and the ltv of the asset being withdrawn.</span>
<span id="L599"><span class="lineNum">     599</span>                 :             :    * @param reservesData The state of all the reserves</span>
<span id="L600"><span class="lineNum">     600</span>                 :             :    * @param reservesList The addresses of all the active reserves</span>
<span id="L601"><span class="lineNum">     601</span>                 :             :    * @param eModeCategories The configuration of all the efficiency mode categories</span>
<span id="L602"><span class="lineNum">     602</span>                 :             :    * @param userConfig The state of the user for the specific reserve</span>
<span id="L603"><span class="lineNum">     603</span>                 :             :    * @param asset The asset for which the ltv will be validated</span>
<span id="L604"><span class="lineNum">     604</span>                 :             :    * @param from The user from which the aTokens are being transferred</span>
<span id="L605"><span class="lineNum">     605</span>                 :             :    * @param reservesCount The number of available reserves</span>
<span id="L606"><span class="lineNum">     606</span>                 :             :    * @param oracle The price oracle</span>
<span id="L607"><span class="lineNum">     607</span>                 :             :    * @param userEModeCategory The users active efficiency mode category</span>
<span id="L608"><span class="lineNum">     608</span>                 :             :    */</span>
<span id="L609"><span class="lineNum">     609</span>                 :<span class="tlaGNC">          23 :   function validateHFAndLtv(</span></span>
<span id="L610"><span class="lineNum">     610</span>                 :             :     mapping(address =&gt; DataTypes.ReserveData) storage reservesData,</span>
<span id="L611"><span class="lineNum">     611</span>                 :             :     mapping(uint256 =&gt; address) storage reservesList,</span>
<span id="L612"><span class="lineNum">     612</span>                 :             :     mapping(uint8 =&gt; DataTypes.EModeCategory) storage eModeCategories,</span>
<span id="L613"><span class="lineNum">     613</span>                 :             :     DataTypes.UserConfigurationMap memory userConfig,</span>
<span id="L614"><span class="lineNum">     614</span>                 :             :     address asset,</span>
<span id="L615"><span class="lineNum">     615</span>                 :             :     address from,</span>
<span id="L616"><span class="lineNum">     616</span>                 :             :     uint256 reservesCount,</span>
<span id="L617"><span class="lineNum">     617</span>                 :             :     address oracle,</span>
<span id="L618"><span class="lineNum">     618</span>                 :             :     uint8 userEModeCategory</span>
<span id="L619"><span class="lineNum">     619</span>                 :             :   ) internal view {</span>
<span id="L620"><span class="lineNum">     620</span>                 :<span class="tlaGNC">          46 :     DataTypes.ReserveData memory reserve = reservesData[asset];</span></span>
<span id="L621"><span class="lineNum">     621</span>                 :             : </span>
<span id="L622"><span class="lineNum">     622</span>                 :<span class="tlaGNC">          69 :     (, bool hasZeroLtvCollateral) = validateHealthFactor(</span></span>
<span id="L623"><span class="lineNum">     623</span>                 :             :       reservesData,</span>
<span id="L624"><span class="lineNum">     624</span>                 :             :       reservesList,</span>
<span id="L625"><span class="lineNum">     625</span>                 :             :       eModeCategories,</span>
<span id="L626"><span class="lineNum">     626</span>                 :             :       userConfig,</span>
<span id="L627"><span class="lineNum">     627</span>                 :             :       from,</span>
<span id="L628"><span class="lineNum">     628</span>                 :             :       userEModeCategory,</span>
<span id="L629"><span class="lineNum">     629</span>                 :             :       reservesCount,</span>
<span id="L630"><span class="lineNum">     630</span>                 :             :       oracle</span>
<span id="L631"><span class="lineNum">     631</span>                 :             :     );</span>
<span id="L632"><span class="lineNum">     632</span>                 :             : </span>
<span id="L633"><span class="lineNum">     633</span>                 :<span class="tlaGNC">          38 :     require(</span></span>
<span id="L634"><span class="lineNum">     634</span>                 :             :       !hasZeroLtvCollateral || reserve.configuration.getLtv() == 0,</span>
<span id="L635"><span class="lineNum">     635</span>                 :             :       Errors.LTV_VALIDATION_FAILED</span>
<span id="L636"><span class="lineNum">     636</span>                 :             :     );</span>
<span id="L637"><span class="lineNum">     637</span>                 :             :   }</span>
<span id="L638"><span class="lineNum">     638</span>                 :             : </span>
<span id="L639"><span class="lineNum">     639</span>                 :             :   /**</span>
<span id="L640"><span class="lineNum">     640</span>                 :             :    * @notice Validates a transfer action.</span>
<span id="L641"><span class="lineNum">     641</span>                 :             :    * @param reserve The reserve object</span>
<span id="L642"><span class="lineNum">     642</span>                 :             :    */</span>
<span id="L643"><span class="lineNum">     643</span>                 :<span class="tlaGNC">        1036 :   function validateTransfer(DataTypes.ReserveData storage reserve) internal view {</span></span>
<span id="L644"><span class="lineNum">     644</span>                 :<span class="tlaGNC">        2072 :     require(!reserve.configuration.getPaused(), Errors.RESERVE_PAUSED);</span></span>
<span id="L645"><span class="lineNum">     645</span>                 :             :   }</span>
<span id="L646"><span class="lineNum">     646</span>                 :             : </span>
<span id="L647"><span class="lineNum">     647</span>                 :             :   /**</span>
<span id="L648"><span class="lineNum">     648</span>                 :             :    * @notice Validates a drop reserve action.</span>
<span id="L649"><span class="lineNum">     649</span>                 :             :    * @param reservesList The addresses of all the active reserves</span>
<span id="L650"><span class="lineNum">     650</span>                 :             :    * @param reserve The reserve object</span>
<span id="L651"><span class="lineNum">     651</span>                 :             :    * @param asset The address of the reserve's underlying asset</span>
<span id="L652"><span class="lineNum">     652</span>                 :             :    */</span>
<span id="L653"><span class="lineNum">     653</span>                 :<span class="tlaGNC">           9 :   function validateDropReserve(</span></span>
<span id="L654"><span class="lineNum">     654</span>                 :             :     mapping(uint256 =&gt; address) storage reservesList,</span>
<span id="L655"><span class="lineNum">     655</span>                 :             :     DataTypes.ReserveData storage reserve,</span>
<span id="L656"><span class="lineNum">     656</span>                 :             :     address asset</span>
<span id="L657"><span class="lineNum">     657</span>                 :             :   ) internal view {</span>
<span id="L658"><span class="lineNum">     658</span>                 :<span class="tlaGNC">          18 :     require(asset != address(0), Errors.ZERO_ADDRESS_NOT_VALID);</span></span>
<span id="L659"><span class="lineNum">     659</span>                 :<span class="tlaGNC">          16 :     require(reserve.id != 0 || reservesList[0] == asset, Errors.ASSET_NOT_LISTED);</span></span>
<span id="L660"><span class="lineNum">     660</span>                 :<span class="tlaGNC">          14 :     require(IERC20(reserve.stableDebtTokenAddress).totalSupply() == 0, Errors.STABLE_DEBT_NOT_ZERO);</span></span>
<span id="L661"><span class="lineNum">     661</span>                 :<span class="tlaGNC">          14 :     require(</span></span>
<span id="L662"><span class="lineNum">     662</span>                 :             :       IERC20(reserve.variableDebtTokenAddress).totalSupply() == 0,</span>
<span id="L663"><span class="lineNum">     663</span>                 :             :       Errors.VARIABLE_DEBT_SUPPLY_NOT_ZERO</span>
<span id="L664"><span class="lineNum">     664</span>                 :             :     );</span>
<span id="L665"><span class="lineNum">     665</span>                 :<span class="tlaGNC">          12 :     require(</span></span>
<span id="L666"><span class="lineNum">     666</span>                 :             :       IERC20(reserve.aTokenAddress).totalSupply() == 0 &amp;&amp; reserve.accruedToTreasury == 0,</span>
<span id="L667"><span class="lineNum">     667</span>                 :             :       Errors.UNDERLYING_CLAIMABLE_RIGHTS_NOT_ZERO</span>
<span id="L668"><span class="lineNum">     668</span>                 :             :     );</span>
<span id="L669"><span class="lineNum">     669</span>                 :             :   }</span>
<span id="L670"><span class="lineNum">     670</span>                 :             : </span>
<span id="L671"><span class="lineNum">     671</span>                 :             :   /**</span>
<span id="L672"><span class="lineNum">     672</span>                 :             :    * @notice Validates the action of setting efficiency mode.</span>
<span id="L673"><span class="lineNum">     673</span>                 :             :    * @param reservesData The state of all the reserves</span>
<span id="L674"><span class="lineNum">     674</span>                 :             :    * @param reservesList The addresses of all the active reserves</span>
<span id="L675"><span class="lineNum">     675</span>                 :             :    * @param eModeCategories a mapping storing configurations for all efficiency mode categories</span>
<span id="L676"><span class="lineNum">     676</span>                 :             :    * @param userConfig the user configuration</span>
<span id="L677"><span class="lineNum">     677</span>                 :             :    * @param reservesCount The total number of valid reserves</span>
<span id="L678"><span class="lineNum">     678</span>                 :             :    * @param categoryId The id of the category</span>
<span id="L679"><span class="lineNum">     679</span>                 :             :    */</span>
<span id="L680"><span class="lineNum">     680</span>                 :<span class="tlaGNC">          17 :   function validateSetUserEMode(</span></span>
<span id="L681"><span class="lineNum">     681</span>                 :             :     mapping(address =&gt; DataTypes.ReserveData) storage reservesData,</span>
<span id="L682"><span class="lineNum">     682</span>                 :             :     mapping(uint256 =&gt; address) storage reservesList,</span>
<span id="L683"><span class="lineNum">     683</span>                 :             :     mapping(uint8 =&gt; DataTypes.EModeCategory) storage eModeCategories,</span>
<span id="L684"><span class="lineNum">     684</span>                 :             :     DataTypes.UserConfigurationMap memory userConfig,</span>
<span id="L685"><span class="lineNum">     685</span>                 :             :     uint256 reservesCount,</span>
<span id="L686"><span class="lineNum">     686</span>                 :             :     uint8 categoryId</span>
<span id="L687"><span class="lineNum">     687</span>                 :             :   ) internal view {</span>
<span id="L688"><span class="lineNum">     688</span>                 :             :     // category is invalid if the liq threshold is not set</span>
<span id="L689"><span class="lineNum">     689</span>                 :<span class="tlaGNC">          34 :     require(</span></span>
<span id="L690"><span class="lineNum">     690</span>                 :             :       categoryId == 0 || eModeCategories[categoryId].liquidationThreshold != 0,</span>
<span id="L691"><span class="lineNum">     691</span>                 :             :       Errors.INCONSISTENT_EMODE_CATEGORY</span>
<span id="L692"><span class="lineNum">     692</span>                 :             :     );</span>
<span id="L693"><span class="lineNum">     693</span>                 :             : </span>
<span id="L694"><span class="lineNum">     694</span>                 :             :     // eMode can always be enabled if the user hasn't supplied anything</span>
<span id="L695"><span class="lineNum">     695</span>                 :<span class="tlaGNC">          34 :     if (userConfig.isEmpty()) {</span></span>
<span id="L696"><span class="lineNum">     696</span>                 :<span class="tlaGNC">          34 :       return;</span></span>
<span id="L697"><span class="lineNum">     697</span>                 :             :     }</span>
<span id="L698"><span class="lineNum">     698</span>                 :             : </span>
<span id="L699"><span class="lineNum">     699</span>                 :             :     // if user is trying to set another category than default we require that</span>
<span id="L700"><span class="lineNum">     700</span>                 :             :     // either the user is not borrowing, or it's borrowing assets of categoryId</span>
<span id="L701"><span class="lineNum">     701</span>                 :<span class="tlaGNC">           8 :     if (categoryId != 0) {</span></span>
<span id="L702"><span class="lineNum">     702</span>                 :             :       unchecked {</span>
<span id="L703"><span class="lineNum">     703</span>                 :<span class="tlaGNC">          14 :         for (uint256 i = 0; i &lt; reservesCount; i++) {</span></span>
<span id="L704"><span class="lineNum">     704</span>                 :<span class="tlaGNC">          12 :           if (userConfig.isBorrowing(i)) {</span></span>
<span id="L705"><span class="lineNum">     705</span>                 :<span class="tlaGNC">           4 :             DataTypes.ReserveConfigurationMap memory configuration = reservesData[reservesList[i]]</span></span>
<span id="L706"><span class="lineNum">     706</span>                 :             :               .configuration;</span>
<span id="L707"><span class="lineNum">     707</span>                 :<span class="tlaGNC">           4 :             require(</span></span>
<span id="L708"><span class="lineNum">     708</span>                 :             :               configuration.getEModeCategory() == categoryId,</span>
<span id="L709"><span class="lineNum">     709</span>                 :             :               Errors.INCONSISTENT_EMODE_CATEGORY</span>
<span id="L710"><span class="lineNum">     710</span>                 :             :             );</span>
<span id="L711"><span class="lineNum">     711</span>                 :             :           }</span>
<span id="L712"><span class="lineNum">     712</span>                 :             :         }</span>
<span id="L713"><span class="lineNum">     713</span>                 :             :       }</span>
<span id="L714"><span class="lineNum">     714</span>                 :             :     }</span>
<span id="L715"><span class="lineNum">     715</span>                 :             :   }</span>
<span id="L716"><span class="lineNum">     716</span>                 :             : </span>
<span id="L717"><span class="lineNum">     717</span>                 :             :   /**</span>
<span id="L718"><span class="lineNum">     718</span>                 :             :    * @notice Validates the action of activating the asset as collateral.</span>
<span id="L719"><span class="lineNum">     719</span>                 :             :    * @dev Only possible if the asset has non-zero LTV and the user is not in isolation mode</span>
<span id="L720"><span class="lineNum">     720</span>                 :             :    * @param reservesData The state of all the reserves</span>
<span id="L721"><span class="lineNum">     721</span>                 :             :    * @param reservesList The addresses of all the active reserves</span>
<span id="L722"><span class="lineNum">     722</span>                 :             :    * @param userConfig the user configuration</span>
<span id="L723"><span class="lineNum">     723</span>                 :             :    * @param reserveConfig The reserve configuration</span>
<span id="L724"><span class="lineNum">     724</span>                 :             :    * @return True if the asset can be activated as collateral, false otherwise</span>
<span id="L725"><span class="lineNum">     725</span>                 :             :    */</span>
<span id="L726"><span class="lineNum">     726</span>                 :<span class="tlaGNC">       13338 :   function validateUseAsCollateral(</span></span>
<span id="L727"><span class="lineNum">     727</span>                 :             :     mapping(address =&gt; DataTypes.ReserveData) storage reservesData,</span>
<span id="L728"><span class="lineNum">     728</span>                 :             :     mapping(uint256 =&gt; address) storage reservesList,</span>
<span id="L729"><span class="lineNum">     729</span>                 :             :     DataTypes.UserConfigurationMap storage userConfig,</span>
<span id="L730"><span class="lineNum">     730</span>                 :             :     DataTypes.ReserveConfigurationMap memory reserveConfig</span>
<span id="L731"><span class="lineNum">     731</span>                 :             :   ) internal view returns (bool) {</span>
<span id="L732"><span class="lineNum">     732</span>                 :<span class="tlaGNC">       40014 :     if (reserveConfig.getLtv() == 0) {</span></span>
<span id="L733"><span class="lineNum">     733</span>                 :<span class="tlaGNC">           6 :       return false;</span></span>
<span id="L734"><span class="lineNum">     734</span>                 :             :     }</span>
<span id="L735"><span class="lineNum">     735</span>                 :<span class="tlaGNC">       26670 :     if (!userConfig.isUsingAsCollateralAny()) {</span></span>
<span id="L736"><span class="lineNum">     736</span>                 :<span class="tlaGNC">       24510 :       return true;</span></span>
<span id="L737"><span class="lineNum">     737</span>                 :             :     }</span>
<span id="L738"><span class="lineNum">     738</span>                 :<span class="tlaGNC">        3240 :     (bool isolationModeActive, , ) = userConfig.getIsolationModeState(reservesData, reservesList);</span></span>
<span id="L739"><span class="lineNum">     739</span>                 :             : </span>
<span id="L740"><span class="lineNum">     740</span>                 :<span class="tlaGNC">        2160 :     return (!isolationModeActive &amp;&amp; reserveConfig.getDebtCeiling() == 0);</span></span>
<span id="L741"><span class="lineNum">     741</span>                 :             :   }</span>
<span id="L742"><span class="lineNum">     742</span>                 :             : </span>
<span id="L743"><span class="lineNum">     743</span>                 :             :   /**</span>
<span id="L744"><span class="lineNum">     744</span>                 :             :    * @notice Validates if an asset should be automatically activated as collateral in the following actions: supply,</span>
<span id="L745"><span class="lineNum">     745</span>                 :             :    * transfer, mint unbacked, and liquidate</span>
<span id="L746"><span class="lineNum">     746</span>                 :             :    * @dev This is used to ensure that isolated assets are not enabled as collateral automatically</span>
<span id="L747"><span class="lineNum">     747</span>                 :             :    * @param reservesData The state of all the reserves</span>
<span id="L748"><span class="lineNum">     748</span>                 :             :    * @param reservesList The addresses of all the active reserves</span>
<span id="L749"><span class="lineNum">     749</span>                 :             :    * @param userConfig the user configuration</span>
<span id="L750"><span class="lineNum">     750</span>                 :             :    * @param reserveConfig The reserve configuration</span>
<span id="L751"><span class="lineNum">     751</span>                 :             :    * @return True if the asset can be activated as collateral, false otherwise</span>
<span id="L752"><span class="lineNum">     752</span>                 :             :    */</span>
<span id="L753"><span class="lineNum">     753</span>                 :<span class="tlaGNC">       13331 :   function validateAutomaticUseAsCollateral(</span></span>
<span id="L754"><span class="lineNum">     754</span>                 :             :     mapping(address =&gt; DataTypes.ReserveData) storage reservesData,</span>
<span id="L755"><span class="lineNum">     755</span>                 :             :     mapping(uint256 =&gt; address) storage reservesList,</span>
<span id="L756"><span class="lineNum">     756</span>                 :             :     DataTypes.UserConfigurationMap storage userConfig,</span>
<span id="L757"><span class="lineNum">     757</span>                 :             :     DataTypes.ReserveConfigurationMap memory reserveConfig,</span>
<span id="L758"><span class="lineNum">     758</span>                 :             :     address aTokenAddress</span>
<span id="L759"><span class="lineNum">     759</span>                 :             :   ) internal view returns (bool) {</span>
<span id="L760"><span class="lineNum">     760</span>                 :<span class="tlaGNC">       39993 :     if (reserveConfig.getDebtCeiling() != 0) {</span></span>
<span id="L761"><span class="lineNum">     761</span>                 :             :       // ensures only the ISOLATED_COLLATERAL_SUPPLIER_ROLE can enable collateral as side-effect of an action</span>
<span id="L762"><span class="lineNum">     762</span>                 :<span class="tlaGNC">          36 :       IPoolAddressesProvider addressesProvider = IncentivizedERC20(aTokenAddress)</span></span>
<span id="L763"><span class="lineNum">     763</span>                 :             :         .POOL()</span>
<span id="L764"><span class="lineNum">     764</span>                 :             :         .ADDRESSES_PROVIDER();</span>
<span id="L765"><span class="lineNum">     765</span>                 :             :       if (</span>
<span id="L766"><span class="lineNum">     766</span>                 :<span class="tlaGNC">          24 :         !IAccessControl(addressesProvider.getACLManager()).hasRole(</span></span>
<span id="L767"><span class="lineNum">     767</span>                 :             :           ISOLATED_COLLATERAL_SUPPLIER_ROLE,</span>
<span id="L768"><span class="lineNum">     768</span>                 :             :           msg.sender</span>
<span id="L769"><span class="lineNum">     769</span>                 :             :         )</span>
<span id="L770"><span class="lineNum">     770</span>                 :<span class="tlaGNC">          24 :       ) return false;</span></span>
<span id="L771"><span class="lineNum">     771</span>                 :             :     }</span>
<span id="L772"><span class="lineNum">     772</span>                 :<span class="tlaGNC">       39957 :     return validateUseAsCollateral(reservesData, reservesList, userConfig, reserveConfig);</span></span>
<span id="L773"><span class="lineNum">     773</span>                 :             :   }</span>
<span id="L774"><span class="lineNum">     774</span>                 :             : }</span>
        </pre>
              </td>
            </tr>
          </table>
          <br>

          <table width="100%" border=0 cellspacing=0 cellpadding=0>
            <tr><td class="ruler"><img src="../../../../../../../../../../../glass.png" width=3 height=3 alt=""></td></tr>
            <tr><td class="versionInfo">Generated by: <a href="https://github.com//linux-test-project/lcov" target="_parent">LCOV version 2.0-1</a></td></tr>
          </table>
          <br>

</body>
</html>
